﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.DomainObjects;
using System.Data.SqlClient;
using System.Data;
using BestLifePOS_Core.Exceptions.DataBase;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifePurchaseOrderMasDetailsByStatus : BestLifeDataAction<List<Purchase_Order>>
    {
         private string GvStatus;
          public BestLifePurchaseOrderMasDetailsByStatus(string PStatus)
        {
            GvStatus = PStatus;
        }

        public override List<Purchase_Order> Body(SqlConnection PConn)
        {
            try
            {
                List<Purchase_Order> LvList = new List<Purchase_Order>();

                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetPODetailsByStatus";
                LvCommand.Parameters.Add(new SqlParameter("@Status", GvStatus));
           
                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {
                    
                    Purchase_Order LvAPO =new Purchase_Order();
                    LvAPO.Po_Id=LvReader.GetValue(0).ToString();
                    LvAPO.Sup_Id = LvReader.GetValue(1).ToString();
                    //LvAPO.Po_Date = LvReader.GetValue(2).ToString();
                    LvAPO.status = LvReader.GetValue(3).ToString();
                    LvAPO.Branch_Id = LvReader.GetValue(4).ToString();
                    LvAPO.User_Id = LvReader.GetValue(5).ToString();
                    //LvAPO.Date_Create = LvReader.GetValue(6).ToString();
                   
                    LvList.Add(LvAPO);
                }


                return LvList;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
    }

